package com.sharkpro.designPattern.myIterator;

/**
 * @author jianxin.wei
 * @description
 * @date 2024/12/16 16:34
 */
public class BookShelfIteratorPre implements MyIterator {
    private BookShelf bookShelf;
    private int index;

    public BookShelfIteratorPre(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = bookShelf.getLength()-1;
    }


    public boolean hasNext() {
        if (index >= 0 ) {
            return true;
        } else {
            return false;
        }
    }

    public Object next() {
        Book book = bookShelf.getBookAt(index);
        index--;
        return  book;
    }


}
